import requests
from api.ihrmEmpManageApi import EmpManageApi
from common.assertTools import common_assert
from common.dbTools import DBTools
from common.getHeader import get_header
from config import TEL


class TestAddEmp(object):
    """添加员工接口的 测试类"""

    def setup_class(self):
        # 创建 emp 实例
        self.emp = EmpManageApi()

        # 准备请求头
        self.req_header = get_header()

    def setup(self):
        """在每个普通方法执行前，自动调用"""
        DBTools.db_iud(f"delete from bs_user where mobile = '{TEL}';")

    def teardown(self):
        """测试结束后，自动调用，删除这个手机号"""
        DBTools.db_iud(f"delete from bs_user where mobile = '{TEL}';")

    def test01_add_success(self):
        """添加员工成功"""

        # 准备添加员工请求体
        req_body = {
            "username": "张三疯007",
            "mobile": TEL,
            "workNumber": "9527"
        }
        resp = self.emp.add_emp(self.req_header, req_body)
        print("添加成功：", resp.json())

        # 断言
        common_assert(resp, 200, True, 10000, "操作成功")

    def test02_mobile_none(self):
        """手机号为空"""

        # 准备添加员工请求体
        req_body = {
            "username": "张三疯007",
            "mobile": None,
            "workNumber": "9527"
        }

        resp = self.emp.add_emp(self.req_header, req_body)
        print("手机号为空：", resp.json())

        # 断言
        common_assert(resp, 200, False, 20002, "新增员工失败")

    def test03_no_params(self):
        """无参"""

        # 准备添加员工请求体
        req_body = None

        resp = self.emp.add_emp(self.req_header, req_body)
        print("无参：", resp.json())

        # 断言
        common_assert(resp, 200, False, 99999, "抱歉，系统繁忙，请稍后重试")
